/*
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 */
function onAddUser(frmID, msgDiv, listtableId,comboid,img,url) {
	var newId = '';
	var char = '';
	var listuser = document.getElementById(comboid);
	var listtable = document.getElementById(listtableId);
	$(frmID).request( {
			asynchronous: false,
			parameters: $(frmID).serialize(true),
			onComplete: function(transport) { 
				var response = transport.responseText || "";
				var pos=response.indexOf('<!');
				content=response.substring(0,pos);
		    	
		    	if(content != "") {
		    		obj = content.evalJSON();
		    		if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
		    		if(obj == null) {
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + response);
		    		}
				if(obj.is_admin==1)
					char = 'x';
				var tr = document.createElement("tr");
					tr.id='user_'+obj.user_id;
					listtable.appendChild(tr);	
				var td_1 = document.createElement("td");
					td_1.innerHTML=obj.user_id;
					tr.appendChild(td_1);	
				var td_2 = document.createElement("td");
					td_2.innerHTML=obj.user_name;
					tr.appendChild(td_2);	
				var td_3 = document.createElement("td");
					td_3.innerHTML=obj.user_email;
					tr.appendChild(td_3);
				var td_4 = document.createElement("td");
					td_4.innerHTML=char;
					tr.appendChild(td_4);	
				var td_5= document.createElement("td");
					tr.appendChild(td_5);
					var ahr = document.createElement("a");
						ahr.className = 'delete';
						ahr.onclick = function(e){
							onDeleteEmail(url,obj.id,msgDiv,comboid,obj.user_id);
						};
						td_5.appendChild(ahr);
						var image = document.createElement("img");
							image.src = img;
							ahr.appendChild(image);
				$(listuser.value).remove();
				}
			}
		});
		
		$(msgDiv).style.display = 'block';
		Fat.fade_element(msgDiv, null, 1500, null, null);

		return false;
}

function onDeleteEmail(url, Id, resp,comboId,UserId) {
	var isOK = -1;
	if(!confirm('Are you sure you want to delete the Email Receiver with Id:' + UserId)) {
		return false;
	}
	var listuser = document.getElementById(comboId);
	new Ajax.Request(url, {
	  method: 'POST',
	  asynchronous: false,
	  parameters:'act=deluser&id=' + Id+'&user_id='+UserId,
	  onSuccess: function(transport) {
			var response = transport.responseText || "";
			var pos=response.indexOf('<!');
			content=response.substring(0,pos);
			obj = content.evalJSON();

    		if(obj == null) {
    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
			var opt= document.createElement("option");
				opt.id = obj.user_id;
				opt.value = obj.user_id;
				opt.innerHTML = obj.user_name+' ('+obj.user_email+')';
				listuser.appendChild(opt);
    		$(resp).update(obj.message);
		}
	});
	
	$(resp).style.display = 'inherit';
	Fat.fade_element(resp, null, 1500, null, null);

		rowID = 'user_' + UserId;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
		
}


